// 创建悬浮按钮
const floatingButton = document.createElement("button");
floatingButton.className = "floating-button";
floatingButton.textContent = "T";

// 是否移动
let isMoving = false;
floatingButton.onmousedown = (e) => {
  isMoving = true;
  console.log("鼠标按下", e);
};
window.addEventListener("mousemove", (e) => {
  if (!isMoving) return;
  const { clientX, clientY } = e;
  let { width, height } = floatingButton.getBoundingClientRect();
  const minRight = Math.min(
    window.innerWidth - width,
    Math.max(window.innerWidth - clientX - width / 2, 0)
  );
  const minTop = Math.min(
    Math.max(0, clientY - height / 2),
    window.innerHeight - height
  );
  floatingButton.style.right = `${minRight}px`;
  floatingButton.style.top = `${minTop}px`;
});

window.addEventListener("mouseup", (e) => {
  isMoving = false;
  console.log("鼠标抬起", e);
});
document.body.appendChild(floatingButton);
